package TCP.moreSent;

import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TCPClientDemo2 {
    public static void main(String[] args) throws Exception {
        System.out.println("=====服务器启动=====");
        ServerSocket serverSocket = new ServerSocket(8888);
        Socket socket = serverSocket.accept();
        InputStream is = socket.getInputStream();
        try {
            while (true){

                byte[] bytes = new byte[1024];
                int len = is.read(bytes);
                String msg = new String(bytes,0,len);
                System.out.println(msg);
                if (msg.equals("886")){
                    is.close();
                    socket.close();
                    serverSocket.close();
                    System.out.println("=====服务器退出=====");
                    break;
                }
                socket.getOutputStream().write("收到".getBytes());
            }
        } catch (Exception e) {
            System.out.println("已断开链接");
        }
    }
}
